package com.vhuomai.product.label.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.product.label.entity.BaseLabelCategory;
import com.vhuomai.product.label.service.LabelCategoryService;
import com.vhuomai.system.constant.UserRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Cui
 */
@Api(tags = "标签目录")
@RestController
@RequestMapping("/api/product")
@Scope(role = UserRole.MANAGER)
public class LabelCategoryController {
    @Autowired
    private LabelCategoryService categoryService;

    @ApiOperation(value = "添加标签目录")
    @PostMapping(value = "/label/category", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> createCategory(@RequestBody BaseLabelCategory categories) {
        categoryService.createCategory(categories);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "更新标签目录")
    @PutMapping(value = "/label/category", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> updateCategory(@RequestBody BaseLabelCategory category) {
        categoryService.updateCategory(category);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除标签目录")
    @DeleteMapping(value = "/label/category", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> deleteCategory(@RequestParam("id") Integer categoryId) {
        categoryService.deleteCategory(categoryId);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "标签目录列表")
    @GetMapping(value = "/label/category", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<BaseLabelCategory>> categoryList() {
        return ServiceResult.success(categoryService.findCategorys());
    }
}
